package com.example.blue_plugin;

import android.app.Activity;


import com.example.blue_plugin.desgin.BaseSDK;
import com.example.blue_plugin.desgin.IMsgEvent;
import com.example.blue_plugin.sdk.NiaoYeSDK;

import java.util.HashMap;
import java.util.Map;

public class DevNiaoYe extends BaseSDK {
    private NiaoYeSDK niaoYeDev;

    @Override
    public void niaoYe() {
        super.niaoYe();
    }

    @Override
    public void initSDK(Activity activity) {
        niaoYeDev = new NiaoYeSDK(activity);
    }


    @Override
    public void connectSDK(IMsgEvent iMsgEvent) {
        if(niaoYeDev == null){
            return;
        }
        niaoYeDev.setOnResultListener(new NiaoYeSDK.OnResultListener() {
            @Override
            public void onCommunicateDisplaySuccess(String json) {
                Map<String, Object> result = new HashMap<>();
                result.put("eventName", "sdkDevJson");
                result.put("devType", "niaoye");
                result.put("json", json);
                iMsgEvent.setSuccessMsg(result);
            }

            @Override
            public void onCommunicateIndexSuccess(String json) {
                Map<String, Object> result = new HashMap<>();
                result.put("eventName", "sdkDevJson");
                result.put("devType", "niaoye");
                result.put("json", json);
                iMsgEvent.setSuccessMsg(result);
            }

            @Override
            public void stateMsg(String state, String msg) {
                Map<String, Object> result = new HashMap<>();
                result.put("eventName", "sdkDevState");
                result.put("state", state);
                result.put("msg", msg);
                result.put("devType", "niaoye");
                iMsgEvent.setSuccessMsg(result);
            }
        });
        niaoYeDev.searchBlutoothList();
    }

    @Override
    public void destroySDK() {
        if(niaoYeDev == null){
           return;
        }
        niaoYeDev.onDestroyCon();
    }
}
